import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import {HttpClient} from "@angular/common/http";
import { PermissionService } from '@core/services/permission.service';
import { ACLService } from '@delon/acl';
import { STData } from '@delon/abc';
import { InoutcosteditComponent } from '../inoutcostedit/inoutcostedit.component';

@Component({
  selector: 'app-inoutcostlist',
  templateUrl: './inoutcostlist.component.html',
  styles: []
})
export class InoutcostlistComponent implements OnInit {
  @ViewChild('st', {static: false})st: TablePageComponent;
  @Input()
  set _param(value){
      console.log(value)
      if(!value) return
      this.param = value
  }
  param:any
  key:string="";
  ip:string="";
  config: SPage = {
    columns: [
      {
        index: 'itemName',
        title: '名称',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'monthlyRent',
        title: '费用元/月',
        fFn(item){
          return item.monthlyRent / 100 + ''
        }
      },
      {
        index: 'remark',
        title: '备注',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'createTime',
        title: '创建时间',
      },
      {
        index: '',
        title: '操作',
        buttons:[
          {
            text:'编辑',
            click:(_record)=>{
              this.editDic(_record)
            }
          },
          {
            text:'删除',
            click:(_record)=>{
              this.deleteData(_record)
            }
          }
        ]
      },
    ],
    reqUrl: "/core/qr/pay/paymentPageByAccount",
  };
  selectedData: object[];
  //数据预处理
  dataProcess(data: STData[]){
    return data;
  }
  //新增费用项
  addCost():void{
    const type = 0
    this.modal.create({
      nzTitle: "新增费用项",
      nzContent: InoutcosteditComponent,
      nzWidth: 800,
      nzComponentParams: {
        type,
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }

  //编辑
  editDic(_param?: object): void {
    const type=1
    this.modal.create({
      nzTitle: "编辑",
      nzContent: InoutcosteditComponent,
      nzWidth: 800,
      nzComponentParams: {
        type,
        _param
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }
  _selectChange(e): void {
    this.selectedData = e;
  }
  //删除
  deleteData(e):void{
    this.modal.confirm({
      nzTitle: '确定删除?',
      nzOnOk: () => {
        this.http.post('/core/qr/pay/delete',{id:e.id}).subscribe((res:any) => {
          if(res.status === '200'){
            this.msg.success('删除成功');
            this.st.reload();
          }else{
            this.msg.warning(res.message)
          }
        })
      }
    })
  }
  constructor(
    private modal: NzModalService,
    private msg: NzMessageService,
    private api: ApiService,
    private http: HttpClient,
    private permission: PermissionService,
    private aclService: ACLService
  ) { }
  ngOnInit() {
  
  }

}
